import 'package:flutter/material.dart';
import 'package:sow_app_i18n/sow_app_i18n.dart';

class TermOfService extends StatefulWidget {
  const TermOfService({Key? key}) : super(key: key);

  @override
  State<TermOfService> createState() => TermOfServiceState();
}

class TermOfServiceState extends State<TermOfService>
    with SingleTickerProviderStateMixin {
  bool accepted = false;
  late final AnimationController controller;
  @override
  void initState() {
    setState(() {
      controller = AnimationController(
          duration: const Duration(milliseconds: 500), vsync: this);
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final Animation<double> offsetAnimation = Tween(begin: 0.0, end: 24.0)
        .chain(CurveTween(curve: Curves.elasticIn))
        .animate(controller)
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          controller.reverse();
        }
      });
    return AnimatedBuilder(
      animation: offsetAnimation,
      builder: (buildContext, child) {
        return Padding(
          padding: EdgeInsets.only(
              left: offsetAnimation.value + 24.0,
              right: 24.0 - offsetAnimation.value),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Checkbox(
                  value: accepted,
                  onChanged: (value) {
                    setState(() {
                      accepted = value ?? false;
                    });
                  }),
              const Text(I18n.term_of_service_msg),
              TextButton(
                  onPressed: () {
                    showDialog(
                      context: context,
                      builder: (BuildContext buildContext) {
                        return const AboutDialog(
                          applicationLegalese: I18n.term_of_service_content,
                        );
                      },
                    );
                  },
                  child: const Text(I18n.term_of_service_btn))
            ],
          ),
        );
      },
    );
  }
}
